// packageC/pages/scanMealOrder/scanMealOrder.js
const app = getApp()
// var QQMapWX = require('../../utils/qqmap-wx-jssdk1.2/qqmap-wx-jssdk.min.js');
const QQMapWX = require('../../../libs/qqmap-wx-jssdk1.2/qqmap-wx-jssdk') //腾讯
var qqmapsdk;
const common = require('../../../public.js')
Page({
    /**
     * 页面的初始数据
     */
    data: {
        currentCardSelectIndex: -1, // <=0,不使用会员折扣或者不是会员，>0使用会员折扣并且是会员 
        // useDiscount:'',// false不使用会员折扣或者不是会员，true使用会员折扣并且是会员
        shareShopCar: '',
        mostgoldToal: 0,
        // glodPrice:0,// 当前选择的金豆
        discountMoney: 0,
        discountsMoney: 0,
        totalNoJoinVipPrice: 0,
        mostMoney: '',
        fyproBenefitItemRate: '',
        listShowMostMoney: 0,
        arrText: [

            {
                isSelect: false,
                name: '暂不使用金豆'
            },
            {
                isSelect: false,
                name: '抵扣￥1.00最高可使用100金豆'
            },
            {
                isSelect: false,
                name: '自定义使用金豆数量'
            },
        ],
        activeIndex: 0,
        showGold: false,
        goldToalXian: '',
        counts: '',
        goldToal: '', // 拥有的金豆数量
        cardDiscountAmount: 0, // 是否使用折扣  0不使用   1使用,
        paymentValue: '',
        discountMoney: 0,


        storeCardId: '',
        cardRate: 1,
        finalItems: [],
        onceRequest: 0,
        timer: '',
        needTotalPrice: 0.00,
        needList: [],
        TableId: '',
        currentSelectNum: 1,
        deskName: '',
        newLatitude: '',
        newLongitude: '',
        useCoupon: false,
        tempUseCoupon: false,
        cardVipJson: '', // 当前选中的会员折扣json
        hasBuy: false, //已购买
        cardVipShow: false,
        memeberSelect: false,
        radioValue: "1",
        commentPlachold: '请输入备注信息,如口味',
        commentValue: "",
        totalPostType: [
            // {"id":591,"dname":"外卖配送","storeId":1479,"feeType":"1","price":10.00,"createTime":1683534351000},
            // {"id":null,"dname":"到店自提","storeId":null,"feeType":"2","price":0,"createTime":null}
        ],
        height: '',
        top: '',
        activeII: 0,
        receiverAddress: '',
        receiverMobile: '',
        receiverName: '',
        storeInfo: '',
        goodList: [],
        totalNormalPrice: 0,
        totalProfitPrice: 0,
        // totalPrice: 0,// 上个页面传递过来的商品总价
        tempTotalPrice: 0,
        totalPackingFee: 0,
        isShow: false,
        selectDate: "",
        dialogh: 0,
        //日期列表和时间列表
        date_list: [],
        time_list: [],
        range: 0,
        start_time: 8,
        end_time: 22,
        step: 30,
        isTimeShow: false,
        hasSelectPAmount: 0,
        hasSelectCityPAmount: 0,
        selectedAddr: false,
        radio: 1,
        cardId: '',
        // storePriceAddress: -1,
        items: [], // 传递给后台的商品json
        counts: 0, //金豆数量
        cityCouponNo: '',
        discountCoupons: [],
        buyerMessage: "",
        remark: "",
        flags: true, //控制开关
        storePrice: 0,
        StoPrice: 0,
        tempStoPrice: 0,
        statusTag: true,
        showStoreCoupons: false,
        checked: false,
        typeIndex: 0, //0是外卖配送 1自提
        postPrice: 0,
        fixedPostPrice: 0,
        paramArr: [],
        addressLists: [],
        latitude: 23.096994,
        longitude: 113.324520,
        markers: [{
            id: 2,
            latitude: 23.098994,
            longitude: 113.322520,
            iconPath: 'http://feiyangimage.oss-cn-shanghai.aliyuncs.com/wxApplets/icon/po.png',
            callout: {
                content: '据您0.5km',
                color: '#000',
                fontSize: 14,
                borderWidth: 2,
                borderRadius: 10,
                borderColor: '#ffff',
                bgColor: '#fff',
                padding: 5,
                display: 'ALWAYS',
                textAlign: 'center'
            },
        }],
        customCalloutMarkerIds: [2],
        postType: 1,
        checkedTime: false

    },
    click_checkedTime(e) {
        let {
            item,
            index
        } = e.currentTarget.dataset
        let selectDate = item
        this.setData({
            selectDate,
            activeII: index
        })
    },
    onChecked(e) {
        this.setData({
            checked: e.detail,
        });
    },
    // 配送方式选择
    topChoice(e) {
        console.log(e, "jkkkkkkkkkkjjjjjjjjj")
        let typeIndex = Number(e.currentTarget.dataset.index)
        console.log(e.currentTarget.dataset, 'ttttttttttttttttttt')
        console.log(typeIndex, "indexindex", this.data.postPrice)
        this.setData({
            typeIndex,
            statusTag: !this.data.statusTag,
            postType: typeIndex == 0 ? 1 : 2,
            postPrice: typeIndex == 0 ? this.data.fixedPostPrice : 0,
            postage: typeIndex == 0 ? this.data.fixedPostPrice : 0,
        }, () => {
            console.log(this.data.postPrice, "pppppppppppppp")
        })
    },
    // 企业券确定
    ComPany_submit() {
        var that = this;

        this.excludeUseFunc(1);






        console.log("打印却确定", this.data.totalPreferential)

        console.log("tempStoPrice", this.data.tempStoPrice)
        this.setData({


            showStoreCoupons: false,
        }, () => {
            console.log('433443444---', that.data.useCoupon, 'xiixixix----', that.data.tempTotalPrice, 'hyuhuhuu----', that.data.totalNormalPrice, 'rrrrrr000-0----', that.data.StoPrice, '==类型==', typeof (that.data.StoPrice));
        })
        // console.log(this.data.comL, "dkdddiokdjd")
    },
    click_company(e) {
        var that = this
        let {
            index,
            item
        } = e.currentTarget.dataset
        if (that.data.totalNormalPrice < item.exceedMoney && that.data.flags && that.data.comL.length != 1) {
            common.showToast('商品总额不能低于满减金额')
            return
        }
        if (that.data.flags && that.data.totalNormalPrice < item.exceedMoney && that.data.comL.length == 1) {
            common.showToast('商品总额不能低于满减金额')
            return
        }
        if (!that.data.flags && item.isSelect != true) {
            common.showToast('此为单选，请先取消选中')
            return
        }
        for (var i = 0; i < this.data.comL.length; i++) {
            if (i == index) { // 当前点击的券 isSelect取反
                console.log('休息==', !this.data.comL[i].isSelect);
                this.data.comL[i].isSelect = !this.data.comL[i].isSelect

            } else { // 其余的券标识为false
                this.data.comL[i].isSelect = false
            }
        }
        if (!item.isSelect) { // 本次选中了
            console.log('aaa----', item.isSelect, '_++++_', this.data.comL);
            var useCoupon = true;
            var currentStoPrice = parseFloat(item.discountsMoney) //单选的优惠金额

            console.log('uuu---', that.data.listShowMostMoney, 'kkkk---', that.data.goldToal, 'pppp----', that.data.totalNormalPrice);





            that.setData({

                mostgoldToal: (that.data.goldToal > that.data.fyproBenefitItemRate * (that.data.totalNormalPrice - currentStoPrice) * 100) ? parseInt(that.data.fyproBenefitItemRate * parseInt((that.data.totalNormalPrice - currentStoPrice) * 100) * 100 / 100) : that.data.goldToal,
            }, () => {
                that.setData({
                    mostMoney: that.data.mostgoldToal / 100,
                    // listShowMostMoney:that.data.mostgoldToal/100,
                    listShowMostMoney: 0, // 每次选中优惠券，都要把金豆折扣置为0。取消选中的话，进行that.data.mostgoldToal/100赋值
                    StoPrice: currentStoPrice,
                })

            })






        } else { // 本次取消选中
            var useCoupon = false;
            console.log('bbbb----', item.isSelect, '_++++_', this.data.comL);
            var currentStoPrice = parseFloat(item.discountsMoney) //单选的优惠金额


            console.log('gjjjjggggg---', that.data.listShowMostMoney, 'ffff---', that.data.goldToal, 'bbbb----', that.data.totalNormalPrice);
            that.setData({

                mostgoldToal: (that.data.goldToal > that.data.fyproBenefitItemRate * (that.data.totalNormalPrice) * 100) ? parseInt(that.data.fyproBenefitItemRate * parseInt((that.data.totalNormalPrice) * 100) * 100 / 100) : that.data.goldToal,
            }, () => {
                console.log('取消选中后---mostgoldToal--', that.data.mostgoldToal, '+_+++listShowMostMoney+', that.data.listShowMostMoney);
                that.setData({
                    // mostMoney:that.data.mostgoldToal/100,
                    mostMoney: 0,
                    // listShowMostMoney:that.data.mostgoldToal/100,
                    listShowMostMoney: 0,
                    StoPrice: 0,
                    goldValue: 0,
                    counts: 0,
                })

            })

            for (var i = 0; i < this.data.arrText.length; i++) {
                if (i == 1) {
                    this.data.arrText[i].isSelect = true
                } else {

                    this.data.arrText[i].isSelect = false
                }
            }



        }
        console.log('嘻嘻hhh', currentStoPrice);

        this.setData({
            // tempUseCoupon:useCoupon,
            // tempStoPrice:currentStoPrice,

            arrText: this.data.arrText,
            useCoupon: useCoupon,





            comL: this.data.comL
        }, () => {
            console.log(this.data.comL)
            var inde = this.data.comL.findIndex(t => t.isSelect == true)
            console.log(inde, "ddd")
            var coupObj = inde != -1 ? this.data.comL[inde] : ''
            console.log(coupObj, "coupObjcoupObj")
            that.setData({
                componyobjs: coupObj
            })
            if (this.data.comL.findIndex(targrt => targrt.isSelect == true) == -1) {
                that.setData({
                    flags: true
                })

            } else {
                that.setData({
                    flags: false
                })
            }
        })

    },
    checkTime() {
        // this.attached()

        this.setData({
            checkedTime: true
        })
    },
    // 优惠券关闭
    onStoreCouponosClose() {
        this.compnayClose()
    },
    compnayClose() {
        // console.log(this.data.comL, "关闭关闭")
        var companyTotal = 0
        for (var i = 0; i < this.data.comL.length; i++) {
            var item = this.data.comL[i]
            if (item.isSelect) {
                companyTotal = companyTotal + this.data.comL[i].discountsMoney
            }
        }
        for (var i = 0; i < this.data.comL.length; i++) {
            this.data.comL[i].isSelect = false
        }
        this.setData({
            storePrice: this.data.storePrice + companyTotal,
            StoPrice: 0,
            comL: this.data.comL,
            flags: true,
            showStoreCoupons: false,
            componyobjs: ''
        })
    },
    // 打开优惠券
    coup_open() {

        // if(this.data.listShowMostMoney){
        //     return common.showToast('优惠券与金豆不可同时使用哦~')
        // }
        // if(this.data.useDiscount){
        //     return common.showToast('会员折扣与优惠券不可同时使用哦~')
        // }
        this.setData({
            showStoreCoupons: true
        })
    },
    // 店铺优惠券线上券
    copuStoreList() {
        var that = this
        var tempJson = {
            storeId: that.data.storeId,
            couponType: 1, //1线上券，2线下券
            token: that.data.token,
            userId: that.data.userInfo.id
        };
        common.wxRequest("/discountCoupon/getMyCouponForStoreByType", "post", tempJson, 'application/x-www-form-urlencoded', function (res) {
            console.log(res);
            if (res.status == 200) {


                var arr = []

                for (var i = 0; i < res.data.length; i++) {

                    res.data[i].beginTime = common.dateFormat('yyyy-MM-dd', res.data[i].beginTime)
                    res.data[i].finishTime = common.dateFormat('yyyy-MM-dd', res.data[i].finishTime)
                    res.data[i].isSelect = false
                    // console.log( res.data[i].exceedMoney)
                    if (that.data.storePrice - res.data[i].exceedMoney > 0) {
                        console.log(res.data[i].exceedMoney)
                        arr.unshift(res.data[i])
                    } else {
                        arr.push(res.data[i])
                    }
                }

                that.setData({
                    comL: arr
                }, () => {
                    console.log('默认---', that.data.comL);
                })
            }
        });
    },
    attached: function () {
        let t = new Date().getTime() + 1800000;
        let d = new Date(t);
        let theMonth = d.getMonth() + 1;
        let theDate = d.getDate();
        let theHours = d.getHours();
        let theMinutes = d.getMinutes();
        let start_day = this.ts_string(new Date().getTime());
        let end_day = this.ts_string(new Date().setDate(new Date().getDate() + this.data.range))
        //获取日期列表
        let date_list = this.getDiffDate(start_day, end_day);
        console.log(date_list, "attachedattachedattachedattached")
        this.setData({
            start_time: theHours
        })
        //获取时间列表 this.data.start_time, this.data.end_time, this.data.step
        let time_list = this.getTimeList(this.data.start_time, this.data.end_time, this.data.step);
        console.log(time_list, "attachedattachedattachedattached222222")
        this.setData({
            // date_time: [date_column, time_column],
            date_list: date_list,
            time_list: time_list,
        }, () => {
            console.log(this.data.time_list, "jjjggguuuu")
        })
        //动画
        this.animation = wx.createAnimation({
            duration: 300
        })
        //500rpx转成px this.data.date_list[0] +
        let dialoghpx = 800 / 750 * wx.getSystemInfoSync().windowWidth
        this.setData({
            dialogh: dialoghpx,
            selectDate: this.data.time_list[0]
        })
    },
    getDiffDate(start, end) {
        let startTime = new Date(start);
        let endTime = new Date(end);
        let dateArr = [];
        while ((endTime.getTime() - startTime.getTime()) >= 0) {
            dateArr.push(this.ts_string(startTime.getTime()));
            startTime.setDate(startTime.getDate() + 1);
        }
        return dateArr;
    },
    zfill(num, length) {
        return (Array(length).join('0') + num).slice(-length);
    },
    //把日期转换成xxxx-xx-xx的形式
    ts_string(timestamp) {
        let d = new Date(timestamp);
        let day = "";
        switch (d.getDay()) {
            case 1:
                day = "周一";
                break;
            case 2:
                day = "周二";
                break;
            case 3:
                day = "周三";
                break;
            case 4:
                day = "周四";
                break;
            case 5:
                day = "周五";
                break;
            case 6:
                day = "周六";
                break;
            case 0:
                day = "周日";
                break;
        }
        let string = (d.getFullYear()) + "-" +
            this.zfill((d.getMonth() + 1), 2) + "-" +
            this.zfill((d.getDate()), 2) + " (" + day + ")"
        return string
    },
    //获取时间区间列表，输入(起始时间，结束时间，步长)
    getTimeList(start, end, step) {
        let start_time = new Date();

        //设置起始时间
        start_time.setHours(start, 0, 0);
        console.log(start_time, "start");
        //设置结束时间
        let end_time = new Date();
        end_time.setHours(end, 0, 0);
        let startG = start_time.getTime(); //起始时间的格林时间
        let endG = end_time.getTime(); //起始时间的格林时间
        let step_ms = step * 60 * 1000;
        let timeArr = [];
        while (startG < endG) {
            let time = this.timeAdd(startG, step_ms);
            timeArr.push(time);
            startG += step_ms;
        }

        return timeArr;
    },
    timeAdd(time1, add) {
        var nd = new Date(time1); //创建时间对象
        //获取起始时间的时分秒
        var hh1 = nd.getHours();
        var mm1 = nd.getMinutes();
        if (hh1 <= 9) hh1 = "0" + hh1;
        if (mm1 <= 9) mm1 = "0" + mm1;
        nd = nd.valueOf(); //转换为毫秒数
        nd = nd + Number(add);
        nd = new Date(nd);
        var hh2 = nd.getHours();
        var mm2 = nd.getMinutes();
        if (hh2 <= 9) hh2 = "0" + hh2;
        if (mm2 <= 9) mm2 = "0" + mm2;
        var time = hh1 + ":" + mm1 + "-" + hh2 + ":" + mm2;
        return time; //时间段
    },
    change: function (e) {
        console.log("滑动")
        const val = e.detail.value;
        //val[0]表示选择的第一列序号，val[1]表示选择的第二列序号
        // this.data.date_list[val[0]] + 
        let select = this.data.time_list[val[1]]
        console.log(select);
        this.setData({
            selectDate: select
        })

    },
    showDialog() {
        this.setData({
            isTimeShow: true
        })
        //先向下移动dialog高度，然后恢复原位从而形成从下向上弹出效果
        this.animation.translateY(this.data.dialogh).translateY(0).step()
        this.setData({
            animation: this.animation.export()
        })
    },
    dimsss() {
        //从原位向下移动dailog高度，形成从上向下的收起效果
        this.animation.translateY(this.data.dialogh).step()
        this.setData({
            animation: this.animation.export()
        })
        //动画结束后蒙层消失
        setTimeout(() => {
            this.setData({
                checkedTime: false
            })
        }, 300)
    },
    cancel() {
        this.triggerEvent("cancel")
        this.dimsss()
    },
    confirm() {
        this.setData({
            checkedTime: false
        })
        // this.triggerEvent("confirm", {
        //     checkedTime: false
        // })
        // this.dimsss()
    },

    //查询店铺配送方式
    getPostType: function () {
        var that = this
        var tempJson = {
            storeId: that.data.storeId,
            userId: that.data.userInfo.id,
            // xpoint: that.data.xpoint,
            // ypoint: that.data.ypoint,
            // xpoint: "117.2852110862732",
            // ypoint: "34.80111369611973"
            xpoint: that.data.newLongitude,
            ypoint: that.data.newLatitude,
        }
        // this.setData({
        //     loadingCount: this.data.loadingCount + 1,
        //     loadingSuccessCount: that.data.loadingSuccessCount - 1
        // })
        common.post('/store/getStorePostTypeForBuyUser', tempJson, function (res) {
            if (res.status === 200) {
                that.setData({
                    postPrice: res.data[0].price ? res.data[0].price : 0,
                    // totalPostType: res.data,
                    // postType: res.data[0] ? res.data[0].feeType : 1,
                    // postage: res.data[0].price ? res.data[0].price : 0,
                    // loadingSuccessCount: that.data.loadingSuccessCount + 1
                }, function () {
                    // that.selectComponent('#vanTabs').resize()
                })
            } else {
                // common.showRequestErrMsg(res)
            }
        }, function () {
            that.setData({
                loadingCount: that.data.loadingCount - 1
            })
        })
    },

    // 下单
    submit: common.throttleFunc(function (e) {
        const that = this
        console.log('postType---', that.data.postType);
        console.log(that.data.selectedAddr, "845661555")

        console.log('needList---', that.data.needList);
        var finalList = [];
        var tempMeedList = [];
        for (var i = 0; i < that.data.needList.length; i++) {
            var item = that.data.needList[i];
            tempMeedList.push({
                skuId: null,
                dishFlavor: null,
                itemId: item.id,
                num: item.eatStandards == "1" ? that.data.currentSelectNum : 1,
                picPath: item.image,
                price: item.price,
                title: item.title,
                price: item.eatStandards == "1" ? that.data.currentSelectNum * item.price : item.price,
            });
        }
        console.log('that.data.items', that.data.items);
        finalList = that.data.items.concat(tempMeedList);
        console.log('finalList---', finalList);
        this.setData({
            finalItems: finalList
        }, () => {
            that.normalPayFunc();
        })
    }, 2000),
    // 下单
    normalPayFunc() {
        console.log('----', this.data.hasBuy, '++++', this.data.memeberSelect);
        // return
        this.setData({
            loadingCount: this.data.loadingCount + 1
        })
        const that = this
        const payment = that.data.storePrice + that.data.postage - (that.data.hasSelectPAmount || that.data.hasSelectCityPAmount) // 实付金额
        var listShowMostMoney = parseFloat(that.data.listShowMostMoney) //单选的优惠金额
        var currentStoPrice = parseFloat(that.data.StoPrice) //单选的优惠金额
        var needTotalPrice = parseFloat(that.data.needTotalPrice) // 必选品总金额
        console.log('----needTotalPrice--', needTotalPrice);

        var realPay = 0;
        if (this.data.hasBuy) { // 已买
            if (this.data.useCoupon) { // 用券
                realPay = ((this.data.totalNormalPrice + this.data.totalNoJoinVipPrice + this.data.totalProfitPrice + this.data.needTotalPrice - this.data.StoPrice) * 100) / 100;
            }
            if (this.data.listShowMostMoney != 0 && this.data.activeIndex != 0) { // 金豆
                realPay = ((this.data.totalNormalPrice + this.data.totalNoJoinVipPrice + this.data.totalProfitPrice + this.data.needTotalPrice - this.data.listShowMostMoney) * 100) / 10;
            }

            if (this.data.currentCardSelectIndex > 0) { // 会员折扣
                realPay = ((this.data.totalNormalPrice + this.data.totalNoJoinVipPrice + this.data.totalProfitPrice + this.data.needTotalPrice) * 100 - (this.data.totalNormalPrice) * (100 - this.data.cardVipJson.payRate * 100)) / 100
            }
            if (!this.data.useCoupon && (this.data.listShowMostMoney == 0 && this.data.activeIndex == 0) && this.data.currentCardSelectIndex <= 0) { // 都没用
                realPay = ((this.data.totalNormalPrice + this.data.totalNoJoinVipPrice + this.data.totalProfitPrice + this.data.needTotalPrice) * 100) / 100;
            }
        } else {
            console.log('未买');
            if (this.data.useCoupon) { // 用券
                console.log('用券---');
                realPay = ((this.data.totalNormalPrice + this.data.totalNoJoinVipPrice + this.data.totalProfitPrice + this.data.needTotalPrice - this.data.StoPrice) * 100) / 100;
            }
            if (this.data.listShowMostMoney != 0 && this.data.activeIndex != 0) { // 金豆
                console.log('金豆---');
                realPay = ((this.data.totalNormalPrice + this.data.totalNoJoinVipPrice + this.data.totalProfitPrice + this.data.needTotalPrice - this.data.listShowMostMoney) * 100) / 10;
            }

            if (!this.data.useCoupon && (this.data.listShowMostMoney == 0 && this.data.activeIndex == 0) && this.data.currentCardSelectIndex <= 0) { // 都没用
                console.log('都没用---');
                realPay = ((this.data.totalNormalPrice + this.data.totalNoJoinVipPrice + this.data.totalProfitPrice + this.data.needTotalPrice) * 100) / 100;
            }
        }


        var calTotalPrice = that.data.totalNormalPrice - currentStoPrice - listShowMostMoney;

        console.log('--1--', currentStoPrice, '--2--', typeof (currentStoPrice), '--3--', listShowMostMoney, '--4--', calTotalPrice, '--55--', that.data.totalNormalPrice);
        var cardDiscount = '';
        if (that.data.currentCardSelectIndex > 0) {
            cardDiscount = (calTotalPrice * (100 - that.data.cardVipJson.payRate * 100) / 100)
        }

        const tempJson = {
            token: that.data.token,
            invitationCode: that.data.invitationCode || '',
            payType: 1,
            cardId: that.data.storeCardId,
            list: [{
                order: {
                    storeDeskId: that.data.TableId,
                    cardDiscountAmount: cardDiscount ? cardDiscount.toFixed(2) : '',
                    // cardDiscountAmount:0.12,
                    isBuyAnnualCard: (!that.data.hasBuy && that.data.memeberSelect) ? 1 : 0, //是否同步开通会员卡  0不开通  1开通     
                    annualCardId: (!that.data.hasBuy && that.data.memeberSelect) ? that.data.cardVipJson.id : '', //  开通会员卡ID
                    deliveryTime: that.data.selectDate,
                    // payment: that.data.totalNormalPrice?that.data.totalNormalPrice.toFixed(2):0,
                    payment: realPay,
                    userId: that.data.userInfo.id,
                    postFee: that.data.postage, //邮费
                    // buyerMessage: that.data.remark,
                    // remark: that.data.remark,
                    buyerMessage: that.data.commentValue,
                    remark: that.data.commentValue,
                    buyerNick: that.data.userInfo.userName,
                    storeId: that.data.storeId,
                    postType: that.data.postType, //1—商城配送;2—到店自提
                    orderType: 1, //商品订单1，活动订单2
                    cityCouponNo: that.data.cityCouponNo,
                    goldPrice: that.data.listShowMostMoney * 100,
                    userDiscountCouponId: that.data.componyobjs ? that.data.componyobjs.udcId : '', //企业券线上
                    discountCoupons: that.data.discountCoupons
                    // discountCoupons:
                },
                items: that.data.finalItems,
                ship: {
                    receiverName: that.data.receiverName || that.data.pickUpSelfName,
                    receiverPhone: '', //可以为空
                    receiverMobile: that.data.receiverMobile || that.data.pickUpSelfPhone,
                    receiverAddress: that.data.receiverAddress,
                    receiverZip: ''
                },
            }]
        };
        // 创建订单
        that.createOrderFunc(tempJson,realPay);
    },
    createOrderFunc(tempJson,realPay){
        var that = this
        //创建订单
        console.log('参数为——--', tempJson);
        console.log('totalProfitPrice---', that.data.totalProfitPrice, 'totalNormalPrice---', that.data.totalNormalPrice, 'totalNoJoinVipPrice---', that.data.totalNoJoinVipPrice);
        // return;
        // 原创建订单接口： /order/createChinaumsOrderForEatAndCardMixSku
        common.postJson('/order/createWxOrZFBOrderForEatAndCardMixSku', tempJson, function (ret) {
            if (ret.status == 200) {
                console.log(ret.data, "jjjjjjj")
                // 0元，不调用支付api
                if (realPay == 0) {
                    clearInterval(that.data.timer);
                    console.log('realyPay为0');
                    wx.navigateTo({
                        url: `/packageC/pages/takeoutComplete/takeoutComplete?orderId=` + ret.data[0].order.id,
                    })
                    return
                }else{// 非0元，调用微信支付
                    that.wxPayFunc(ret)
                }
               
            } else {
                common.showRequestErrMsg(ret)
            }
        }, function () {
            that.setData({
                loadingCount: that.data.loadingCount - 1
            })
        })
    },
    wxPayFunc(ret){
        var that = this
        var tempJson = {
            userId: that.data.userInfo.id,
            token: that.data.token,
            orderId: ret.data[0].order.id,
            xcxOpenid: that.data.openid,
        }
        that.setData({
            loadingCount: that.data.loadingCount + 1
        })

        console.log('会员卡id---', that.data.cardId);
        // 原下单支付接口：/wxxcxPayGoodsForFYPlatformChinaUms
        common.wxPayRequest('/wxxcxPayForGoods', tempJson, function (res) {
            console.log(res, "lilili")

            if (res.status !== 200) {
                common.showRequestErrMsg(res)
            } else {
                //微信支付
                wx.requestPayment({
                    'timeStamp': res.data.timeStamp,
                    'nonceStr': res.data.nonceStr,
                    'package': res.data.package,
                    'signType': res.data.signType,
                    'paySign': res.data.paySign,
                    'success': function (res) {
                        console.log('res----', res)
                        common.showToast('支付成功', 'success')
                        clearInterval(that.data.timer);
                        if (that.data.cardId != '') {
                            console.log('cardId有值')
                            wx.navigateTo({
                                url: `/packageC/pages/takeoutTobepaid/takeoutTobepaid?orderId=${ret.data[0].order.id}`,
                            })
                        } else {
                            console.log('cardId无值')
                            // wx.navigateBack({
                            //     delta: 1
                            // })
                            console.log('a链接---', `/packageC/pages/takeoutComplete/takeoutComplete?orderId=` + ret.data[0].order.id)
                            wx.redirectTo({
                                url: `/packageC/pages/takeoutComplete/takeoutComplete?orderId=` + ret.data[0].order.id,
                            })
                            // wx.navigateTo({
                            //     url: `/packageC/pages/takeoutComplete/takeoutComplete?orderId=` + ret.data[0].order.id,
                            // })
                        }

                    },
                    'fail': function (res) {
                        console.log('fail---', res);
                        clearInterval(that.data.timer);
                        if (that.data.cardId != '') {
                            console.log('asdffg');
                            wx.navigateTo({
                                url: '/pages/ScenicArea/NianCardOrder/index?titles=1',
                            })
                        } else {
                            console.log('uuuuii');
                            // wx.redirectTo({
                            //     url: '/packageA/pages/Goods/goodsOrder/goodsOrderList/index?type=1',
                            // })
                            wx.redirectTo({
                                url: '/packageA/pages/Goods/goodsOrder/goodsOrderDetail/index?orderId=' + ret.data[0].order.id,
                            })



                        }

                        if (res.errMsg === 'requestPayment:fail cancel') {} else {
                            common.showToast(res.errMsg)
                        }
                    },
                    'complete': function (res) {
                        console.log('完成----', res)
                    }
                })
            }
        }, function () {
            that.setData({
                loadingCount: that.data.loadingCount - 1
            })
        })
    },

    onLoad(options) {
        clearInterval(this.data.timer);
        console.log('options---', options);
        const that = this
        //获取胶囊位置
        this.attached()
        that.mapCtx = wx.createMapContext('myMap')
        qqmapsdk = new QQMapWX({
            //   key: 'W57BZ-JDB6X-XPA4H-Z76MI-73FF2-24BT4'
            key: 'SUOBZ-SJG6B-PQQUT-JL75Z-3F3Z5-AAFJ3' // 原P35BZ-K2WAS-GUZO7-6IRVW-IYBQV-ZUB6B
        });
        let capsule = wx.getMenuButtonBoundingClientRect()
        this.setData({
            height: capsule.height,
            top: capsule.top,

        })


        common.getLocalUserInfo(function (success, data) {
            if (success) {
                console.log(data, "5588444551", '---options--', options)
                console.log('最新的价格--', parseInt(options.totalNormalPrice));
                that.setData({
                    userInfo: data.user,
                    token: data.token,
                    openid: data.openid,
                    // pickUpSelfName: data.user.realName,
                    pickUpSelfPhone: data.user.phone,
                    storeId: parseInt(options.storeId),
                    // totalPrice: parseInt(options.totalPrice),
                    storePrice: parseFloat(options.totalNormalPrice),
                    totalNormalPrice: parseFloat(options.totalNormalPrice),
                    cardId: app.globalData.cardId,
                    storeCardId: options.storeCardId,

                    deskName: options.deskName,
                    currentSelectNum: options.currentSelectNum ? options.currentSelectNum : 1,
                    TableId: options.TableId,
                    shareShopCar: options.shareShopCar,
                }, () => {



                    console.log('storeCardId---', that.data.storeCardId, '==传递的totalNormalPrice--', that.data.totalNormalPrice);
                    // that.getShopDes()


                    that.getStoreInfo();
                    that.getUserAssets()

                    if (that.data.shareShopCar == 2) { // 不共享
                        console.log('不共享---');
                        that.getCartNum()

                    } else {
                        console.log('共享---');
                        that.getCartNum()
                        that.scoketFunc();
                    }


                })

                if (!that.data.selectedAddr) {
                    // that.addressList() //地址列表
                }
                if (options.selectedAddr) {
                    console.log("1111111111111111111111111111111111111111")
                    // 已经选择地址的逻辑，当前逻辑是从选择地址列表返回
                    that.setData({
                        selectedAddr: options.selectedAddr,
                        receiverName: options.receiverName,
                        receiverMobile: options.receiverMobile,
                        receiverAddress: options.receiverAddress,
                        xpoint: options.longitude,
                        ypoint: options.latitude,
                        postPrice: options.postPrice,
                        StoPrice: options.StoPrice,
                        fixedPostPrice: options.postPrice,
                    })
                } else {
                    that.copuStoreList()
                    //    that.addressList()
                    //    that.getCardForTakeawayFunc();

                    that.requestOnceFunc();

                    console.log("22222222222222222222222222222222222222222")

                    that.setData({
                        storeId: parseInt(options.storeId),
                    }, function () {
                        // that.getPostType() //根据位置查询店铺配送方式
                    })


                    // // 默认进入 - 未选择地址，从下单页面进入
                    // getApp().getLocation(function (data) {
                    //     console.log('经11纬度为---',data);
                    //     that.data.lon = data.longitude
                    //     that.data.lat = data.latitude
                    //     that.setData({
                    //       storeId: parseInt(options.storeId),
                    //         xpoint: data.longitude,
                    //         ypoint: data.latitude
                    //     }, function () {
                    //         // that.getPostType() //根据位置查询店铺配送方式
                    //     })
                    // })
                }
            }
        }, true)

    },
    getUserAssets() { // 获取余额
        const that = this
        const tempJson = {
            userId: that.data.userInfo.id,
            token: that.data.token
        }
        console.log('fffgggg');
        common.post('/userDeposit/getUserAssetsGold', tempJson, function (res) {
            if (res.status === 200) {
                console.log('getUserAssetsGoldp----', res);
                var totalMoney = res.data.totalMoney;

                // totalMoney = 800;
                that.setData({

                    goldToal: totalMoney, //  totalMoney
                    counts: totalMoney,
                    goldToalTwo: totalMoney,
                    // totalNormalPrice表示的是上个界面传过来的总价(除掉不计算折扣的)
                    mostgoldToal: (totalMoney > that.data.fyproBenefitItemRate * that.data.totalNormalPrice * 100) ? parseInt(that.data.fyproBenefitItemRate * parseInt(that.data.totalNormalPrice * 100) * 100 / 100) : totalMoney,
                }, () => {
                    console.log('解决===', that.data.mostgoldToal);
                    console.log('ghhhh--', totalMoney);
                    console.log('aaa--', that.data.fyproBenefitItemRate);
                    console.log('fff--', that.data.totalNormalPrice);
                    console.log('bbb--', that.data.fyproBenefitItemRate * that.data.totalNormalPrice * 100);
                    console.log('ccc--', parseInt(that.data.fyproBenefitItemRate * parseInt(that.data.totalNormalPrice * 100) * 100 / 100));
                    console.log('ddddd--', that.data.goldToal);
                    that.setData({
                        mostMoney: that.data.mostgoldToal / 100,

                    })
                })
            } else {
                common.showRequestErrMsg(res)

            }
        })
    },
    scoketFunc() {
        var that = this;
        that.data.timer = setInterval(function() {

        // console.log('111哈哈哈哈哈哈');
        that.getCartNum()

        }, 1500);
    },



    requestOnceFunc() {

        this.cardsList();
        return;
        var that = this

        common.get('/userAnnualCard/checkIsBuyStoreAnnualCard', {
            userId: this.data.userInfo.id,
            storeId: that.data.storeId,
            token: this.data.token
        }, res => {
            console.log('checkIsBuyStoreAnnualCard---', res)
            that.setData({
                hasBuy: res.data ? true : false,
                useDiscount: res.data ? true : false,
                memeberSelect: res.data ? true : false,
            })
            if (res.data) { // 权益商品
                that.reLists(res.data);


            } else {
                console.log('嘻嘻嘻');
                var json = {};
                json.payRate = 1;
                that.setData({
                    cardVipJson: json
                })

            }

        })

    },


    reLists(idx) {
        var that = this
        common.get('/userAnnualCard/getCardList', {
            cardId: idx
        }, res => {
            if (res.status === 200) {
                console.log('33---', res);

                var tempData = res.data[0];
                that.setData({
                    cardVipJson: tempData,
                    cardRate: tempData ? tempData.payRate.toFixed(2) * 100 / 10 : 1,
                    cardVipShow: tempData ? true : false,
                }, () => {


                })




            } else {
                // common.showRequestErrMsg(res)
            }
        })
    },





    // getCardForTakeawayFunc(){

    //     var that = this
    //     let tempJson = {
    //         storeId: that.data.storeId,
    //         // userId: that.data.userInfo.id,
    //         // token: that.data.token
    //     }
    //     //外卖店铺的否已经有会员卡
    //     common.post('/userAnnualCard/getCardForTakeawayRec', tempJson, function (res) {
    //         console.log('会员卡会员',res);
    //         if (res.status === 200) {
    //             var tempData = res.data;
    //             that.setData({
    //                 cardVipJson:res.data,
    //                 cardRate:res.data? res.data.payRate.toFixed(2)*100/10:1,
    //                 cardVipShow:res.data?true:false,
    //             },()=>{

    //                 if(tempData==null){
    //                     console.log('嘻嘻嘻');
    //                     var json = {};
    //                     json.payRate = 1;
    //                     that.setData({
    //                         cardVipJson:json
    //                     })

    //                 }
    //             })
    //             if(res.data){
    //                 that.isPayFunc(res.data.id);
    //             }

    //         } else {
    //             common.showRequestErrMsg(res)
    //         }
    //     }, function () {

    //     })
    // },
    // 获取购物车数量
    getCartNum() {
        const that = this
        let tempJson = {
            storeId: that.data.storeId,
            userId: that.data.userInfo.id,
            token: that.data.token,
            storeDeskId: that.data.TableId,
        }
        common.wxRequest(that.data.shareShopCar == 2 ? '/cart/listByStoreSku' : '/cart/listForStoreDeskSku', 'post', tempJson, 'application/x-www-form-urlencoded', function (res) {
            that.data.onceRequest = that.data.onceRequest + 1;
            if (res.status === 200) {
                // let totalPrice = 0;
                let totalNormalPrice = 0;
                let totalProfitPrice = 0;
                let totalNoJoinVipPrice = 0;
                let totalPackingFee = 0;
                let totalNum = res.data.totalNum
                res.data.list.map((item, index) => {
                    // itemCard;//1：会员卡商品，2：普通商品
                    if (item.itemCard == 2) {

                        if (parseInt(item.payRateFlag) == 0) { // 不参与会员折扣 
                            console.log('不参与', index);
                            totalNoJoinVipPrice = item.num * item.price + totalNoJoinVipPrice;
                        } else {
                            console.log('参与', index);
                            totalNormalPrice = item.num * item.price + totalNormalPrice;
                        }
                    } else {
                        totalProfitPrice = item.num * item.price + totalProfitPrice;
                    }
                    // totalPrice = item.num * item.price + totalPrice;
                    // 外卖没有包装费，下面一行代码可注释
                    totalPackingFee = totalPackingFee + item.packingFee * item.num;
                })
                var storeprice;
                console.log(app.globalData.discount, "app.globalData.discountapp.globalData.discount")
                console.log('ddd----', that.data.totalNoJoinVipPrice);



                let items = []
                res.data.list.map((item, index) => {
                    console.log(item, "1111111")
                    items.push({
                        skuId: item.dishFlavor,
                        dishFlavor: item.dishFlavor,
                        itemId: item.itemId,
                        num: item.num,
                        title: item.title,
                        price: item.price,
                        totalFee: (item.num * item.price),
                        picPath: item.image,
                    })
                })
                console.log(items)


                that.setData({
                    items: [...items],
                    goodList: res.data.list, //商品列表
                    cartNum: totalNum,
                    goodsCount: 0,

                    totalNormalPrice,
                    totalNoJoinVipPrice,
                    totalProfitPrice,
                    totalPackingFee,
                    // storePrice: storeprice,

                }, () => {
                    console.log('h-h---', that.data.onceRequest);
                    if (that.data.onceRequest <= 1) {
                        console.log('执行一次---');
                        that.getNeedList(items, that.data.storeId);
                    } else {
                        console.log('嘻哈000');
                    }

                })

            } else {
                // wx.showToast({
                //     title: res.msg ? res.msg : '添加失败',
                // })

                console.log('购物车没东西=====');

                that.setData({

                    goodList: [], //商品列表
                    items: [],
                    // totalPrice:0.00,
                    totalNormalPrice: 0,
                    totalNoJoinVipPrice: 0,
                    totalProfitPrice: 0,

                }, () => {


                })



            }
        })
    },


    goBack() {
        clearInterval(this.data.timer);
        const pages = getCurrentPages();
        const prevPage = pages[pages.length - 2]; //上一个页面
        // 从朋友圈进入的时候，页面栈为空，这里需要判断是否有上个页面
        if (prevPage) {
            wx.navigateBack({
                delta: 1
            })
        } else {
            wx.redirectTo({
                url: '/pages/index/index',
            })
        }
    },
    // 地址列表
    // addressList() {
    //     const that = this
    //     const tempJson = {
    //         storeId:that.data.storeId,
    //         userId: that.data.userInfo.id,
    //         token: that.data.token
    //     }
    //     common.post('/user/ship/listForStoreTakeaway', tempJson, function (res) {
    //         if (res.status === 200) {
    //             let obj = ''
    //             console.log(res, "55555")
    //             if (Array.isArray(res.data) && res.data.length) {
    //                  // isDefault为1,就立刻返回,不在往下遍历
    //                  obj = res.data.find((v) => v.deliveredFlag == 1)
    //                 }
    //                 console.log('--333333-',obj,'---类型',typeof(obj));
    //                 // return
    //                 if(obj){

    //                     console.log('默认地址复制---',obj);
    //                     that.setData({
    //                         selectedAddr: obj.receiverAddress,
    //                         receiverName: obj.receiverName,
    //                         receiverMobile: obj.receiverMobile,
    //                         receiverAddress: obj.receiverAddress,
    //                         newLatitude:obj.ypoint,
    //                         newLongitude:obj.xpoint,
    //                     },()=>{
    //                         that.getPostType();
    //                     })
    //                 }



    //         } else {
    //             common.showRequestErrMsg(res)

    //         }
    //     })
    // },



    onChange(e) {
        let {
            value
        } = e.detail
        this.setData({
            commentValue: value
        })
    },
    goBackFunc() {
        wx.navigateBack({
            delta: 1,
        })
    },
    onRadioChange(event) {
        console.log('event--', event.detail);
        this.setData({
            radioValue: event.detail == "1" ? 0 : "1",
        }, () => {
            console.log('---radioValue--', this.data.radioValue);
        });
    },
    selectMemeberFunc() {

        var that = this;
        console.log('tt---', that.data.memeberSelect);
        that.setData({
            memeberSelect: that.data.memeberSelect == true ? false : true
        }, () => {
            console.log('最终选择状态', that.data.memeberSelect);
        })
    },
    seePrivilegeFunc() {
        if (this.data.hasBuy) {
            this.data.cardVipJson.annualCardId = this.data.cardVipJson.id;
            var objs = JSON.stringify(this.data.cardVipJson)
            console.log('222', objs);
            wx.navigateTo({
                url: '/packageA/pages/indexnian/indexni?obj=' + encodeURIComponent(objs),
            })
        } else {
            // 

            let url = `/pages/myNian/payCard/payCard?cardId=${this.data.cardVipJson.id}&distributorId=${this.data.cardVipJson.managerId}`
            common.tiao_Zhuan(url)
        }
    },
    // 判断是否支付
    isPayFunc(idx) {
        var that = this
        common.get('/userAnnualCard/checkUserBoughtCard', {
            userId: this.data.userInfo.id,
            cardId: idx,
            token: this.data.token
        }, res => {
            console.log(res)

            that.setData({
                hasBuy: res.status === 1 ? true : false,
                memeberSelect: res.status === 1 ? true : false,
            }, () => {
                console.log('ssss---', that.data.hasBuy);
            })
            // if (res.status === 1) {

            //     // common.showToast(res.msg)
            //     // that.cardsList()
            // }
        })
    },

    getNeedList(items, storeId) {
        var that = this
        var tempJson = {
            storeId: storeId,

        }
        common.get('/store/getEatNeedGoodsList', tempJson, res => {
            console.log('2222---getEatNeedGoodsList---', res);
            that.setData({
                needList: res.data
            })
            var needTotalPrice = 0.00;
            for (var i = 0; i < res.data.length; i++) {
                var item = res.data[i];
                var json = {};
                if (item.eatStandards == "1") {
                    needTotalPrice = that.data.currentSelectNum * item.price + needTotalPrice;
                }
                if (item.eatStandards == "2") {
                    needTotalPrice = item.price + needTotalPrice;
                }
                // items.push({
                //     dishFlavor: null,
                //     itemId: item.id,
                //     num: item.eatStandards=="1"?that.data.currentSelectNum:1,
                //     picPath: item.image,
                //     price: item.price,
                //     title: item.title,
                //     price:item.eatStandards=="1"?that.data.currentSelectNum * item.price:item.price,
                // });

            }
            console.log('必需品总价--', needTotalPrice);
            that.setData({
                needTotalPrice,

            })



        })
    },

    cardListSelectFunc() {
        this.setData({
            cardListSelectShow: true
        })
    },
    // 金豆弹框
    goldFlag() {
        // return;
        // if (this.data.useCoupon) {
        //     common.showToast('优惠券和金豆不可同时使用哦~')
        //     return
        // }
        // if(this.data.useDiscount){
        //     return common.showToast('会员折扣与金豆不可同时使用哦~')
        // }



        //付款金额满100元才能使用金豆
        // if (this.data.paymentValue < 100) {
        //     common.showToast('付款金额满100可用')
        //     return
        // }
        console.log(parseFloat((this.data.paymentValue)))
        console.log(this.data.goldToal / 100)
        console.log(parseFloat((this.data.paymentValue)) - (this.data.counts / 100), "555555555")
        if (this.data.goldToal < 100) {
            common.showToast('暂不可用')
            return

        }
        if (parseFloat((this.data.paymentValue)) - (this.data.goldToal / 100) <= 0) {
            this.setData({
                goldToalXian: (this.data.paymentValue * 1000 * 100) / 1000,
                // counts:this.data.paymentValue*100
            })
        } else {
            this.setData({
                goldToalXian: this.data.goldToal,
                // counts:this.data.goldToal
            })
        }
        // if (this.data.paymentValue == '') {
        //     common.showToast('请输入金额')
        //     return
        // }
        // if (this.data.paymentValue <1) {
        //     common.showToast('付款金额大于1元可使用金豆')
        //     return
        // }
        this.setData({
            showGold: true
        })
    },
    onClose() {
        var that = this

        this.setData({
            showGold: false,
            cardListSelectShow: false,
        });
    },

    card_item_index(e) {
        var that = this
        let {
            index,
            item
        } = e.currentTarget.dataset
        console.log('index---', index, '-----item---', item);

        for (var i = 0; i < this.data.nianList.length; i++) {
            if (index == i) {
                this.data.nianList[i].isSelect = true

            } else {

                this.data.nianList[i].isSelect = false


            }
        }
        this.setData({
            currentCardSelectIndex: index,
            nianList: this.data.nianList
        })


    },
    click_index(e) {
        var that = this
        let {
            index,
            item
        } = e.currentTarget.dataset
        // let paymentValue = parseInt(this.data.paymentValue)
        this.setData({
            goldBean: false,
            // paymentValue,
        }, () => {
            console.log(this.data.counts, "444447777777777777777")
            console.log(index, "indexinxe")

            if (this.data.useCoupon) { // 用券了(点击了确定)
                this.setData({
                    mostgoldToal: (that.data.goldToal > that.data.fyproBenefitItemRate * (that.data.totalNormalPrice - that.data.StoPrice) * 100) ? parseInt(that.data.fyproBenefitItemRate * parseInt((that.data.totalNormalPrice - that.data.StoPrice) * 100) * 100 / 100) : that.data.goldToal,



                }, () => {
                    console.log('xcxccc--', that.data.mostgoldToal);
                    this.setData({
                        mostMoney: that.data.mostgoldToal / 100,
                        listShowMostMoney: that.data.mostgoldToal / 100,
                    }, () => {
                        this.finalDealFunc(index);
                    })

                })
            } else {
                this.setData({


                    mostgoldToal: (that.data.goldToal > that.data.fyproBenefitItemRate * (that.data.totalNormalPrice) * 100) ? parseInt(that.data.fyproBenefitItemRate * parseInt((that.data.totalNormalPrice) * 100) * 100 / 100) : that.data.goldToal,

                }, () => {
                    this.setData({
                        mostMoney: that.data.mostgoldToal / 100,
                        listShowMostMoney: that.data.mostgoldToal / 100,
                    }, () => {
                        this.finalDealFunc(index);
                    })

                })
            }


        })


    },


    finalDealFunc(index) {

        var that = this;
        var suitGold = '';
        if (index == 0) {
            this.setData({
                counts: 0,
                goldValue: '',
                // othercounts: 0
            })
        } else if (index == 1) {

            console.log('前者', parseFloat(that.data.mostgoldToal), '--后者---', that.data.goldToal);

            // var suitGold = '';
            if (that.data.goldToal > parseFloat(that.data.mostgoldToal)) { // 拥有>最高可用
                console.log('ff');
                suitGold = parseFloat(that.data.mostgoldToal);
            } else { // 拥有<最高可用
                console.log('gg');
                suitGold = that.data.goldToal;
            }
            console.log('suitGold---', suitGold);


            this.setData({
                counts: suitGold,
                goldValue: '',
                // counts: this.data.goldToalXian
            })
        } else if (index == 2) {
            this.setData({
                counts: 0,
                // othercounts: 0,
            })
        }


        this.setData({
            activeIndex: index,


        })

        for (var i = 0; i < this.data.arrText.length; i++) {
            if (this.data.activeIndex == i) {
                this.data.arrText[i].isSelect = true
            } else {

                this.data.arrText[i].isSelect = false
            }
        }
        console.log('3434===', this.data.counts);

        this.setData({

            listShowMostMoney: this.data.counts / 100,
            // listShowMostMoney:suitGold/100,
            arrText: this.data.arrText
        })

    },


    //购买数量  计算数量金额加
    goldNumChange(e) {
        var that = this;
        var num;
        if (e.detail == '' || !e.detail || e.detail == 0) {
            var counts = 0
        } else {

            counts = parseInt(e.detail)
            console.log('nnnn--', counts);

            var mostCanUse = that.data.mostgoldToal;

            console.log('拥有--', this.data.goldValue, '===最高可用', mostCanUse);
            if (this.data.goldToal > mostCanUse) { // 拥有>最高可用
                if (counts < 100) { // 输入小于100, 提示金豆数量最低使用100

                } else if (counts >= 100 && counts <= mostCanUse) { // 大于等于100,小于等于最高可用  正常
                    this.setData({
                        goldValue: counts

                    })
                } else {
                    common.showToast('您输入的数量超限')
                    counts = 0
                    this.setData({
                        goldValue: '',
                        listShowMostMoney: 0
                    })
                }
            } else { // 拥有<最高可用
                if (counts < 100) { // 输入小于100, 提示金豆数量最低使用100

                } else if (counts >= 100 && counts <= this.data.goldToal) { // 大于等于100,小于等于最高可用  正常
                    console.log('----counts---', counts);
                    this.setData({
                        goldValue: counts

                    })
                } else {
                    common.showToast('您输入的数量超限')
                    counts = 0
                    this.setData({
                        goldValue: '',
                        listShowMostMoney: 0
                    })
                }
            }




        }

        that.setData({
            counts, //金豆数量
            // othercounts: counts
        }, () => {
            this.setData({
                // listShowMostMoney: parseInt(counts*100)/100,
                listShowMostMoney: parseInt(counts * 100) / 100 / 100,
            })
        })
    },

    onBlur(e) {
        var that = this;
        var num;
        if (e.detail.value == '' || !e.detail.value || e.detail.value == 0) {
            var counts = 0
        } else {
            counts = parseInt(e.detail.value)
            console.log('fff---', counts);
            if (counts < 100) {
                common.showToast('最低使用100个金豆')
                counts = 0
                this.setData({
                    goldValue: '',
                    listShowMostMoney: 0
                })
                return
            }
        }

    },
    excludeUseFunc(type) {
        if (type != 1) { // 本次是金豆或者会员抵扣。 选了优惠券的话，将优惠券置空  this.data.useCoupon
            for (var i = 0; i < this.data.comL.length; i++) {

                this.data.comL[i].isSelect = false

            }
            this.setData({
                useCoupon: false,
                StoPrice: 0,
                flags: true, // 可以选择
                comL: this.data.comL
            })

        }



        if (type != 2) { // 本次是优惠券和会员抵扣。 选了金豆的话，将金豆置空  this.data.listShowMostMoney>0

            for (var i = 0; i < this.data.arrText.length; i++) {

                this.data.arrText[i].isSelect = false;

            }
            this.setData({
                listShowMostMoney: 0,
                activeIndex: 0,
                arrText: this.data.arrText,
            })
        }



        if (type != 3) { // 本次是优惠券和金豆。 选了会员折扣的话，将会员折扣置空 this.data.currentCardSelectIndex>0
            for (var i = 0; i < this.data.nianList.length; i++) {
                this.data.nianList[i].isSelect = false
            }

            this.setData({
                currentCardSelectIndex: -1,
                currentVipDiscount: 1,
                nianList: this.data.nianList,
            }, () => {
                console.log('fff====', this.data.currentCardSelectIndex);
            })
        }





    },
    submit_vip_discount_sure() {

        this.excludeUseFunc(3);
        console.log('会员卡索引=---', this.data.currentCardSelectIndex);
        this.setData({
            cardVipJson: this.data.nianList[this.data.currentCardSelectIndex],
            currentVipDiscount: this.data.nianList[this.data.currentCardSelectIndex].payRate,
            cardListSelectShow: false,
        })
    },
    // 金豆提交
    submit_clicks() {

        this.excludeUseFunc(2);



        // if(this.data.goldValue<100){
        //       common.showToast('最低使用100个金豆')
        //     return;
        // }

        this.setData({
            showGold: false,
        })

    },

    getStoreInfo() {
        var that = this;
        this.setData({
            loading: true
        })
        console.log('xxxx-');
        const param = {
            storeId: this.data.storeId,
            // employeeId: this.data.employeeUserId,
            employeeId: "",
            userId: this.data.userInfo.id,
        }
        console.log('jjj', param);
        common.post('/store/getStoreAndBranchInfo',
            param,
            res => {
                console.log('信息为--', res);
                if (res.status === 200) {
                    this.setData({
                        // storeInfo: res.data.store,
                        fyproBenefitItemRate: res.data.fyproBenefitItemRate,
                        // payRate:res.data.payRate==1?0:res.data.payRate,
                        // storeName: res.data.name,
                        // storeImage:  res.data.storeImage,

                    }, function () {
                        that.getUserAssets()
                    })




                }
            },
            () => {
                console.log('dsadsdsd');
                this.setData({
                    loading: false
                })
            })
    },


    // cancelDiscountClick(e){

    //     if(this.data.useCoupon){
    //         return common.showToast('优惠券与会员折扣不可同时使用哦~')
    //     }

    //     if(this.data.listShowMostMoney){
    //         return common.showToast('金豆券与会员折扣不可同时使用哦~')
    //     }
    //     var that = this
    //     let {
    //         index
    //     } = e.currentTarget.dataset

    //     this.setData({
    //         useDiscount:!index,
    //     },()=>{

    //         console.log('取消使用',this.data.useDiscount);
    //     })
    // },

    // 我购买会员卡列表接口-------------------------------------------------------------------------------
    cardsList() {
        var that = this
        // /userAnnualCard/getUserCardProductList

        common.get('/userAnnualCard/getUserAnnualCardListForOneStore', {
            storeId: that.data.storeId,
            userId: that.data.userInfo.id,
            token: that.data.token
        }, res => {
            if (res.status === 200) {
                // for (var i = 0; i < res.data.length; i++) {
                //     res.data[i].validTime = that.time(res.data[i].validTime)
                //     // res.data[i].discount = 0.3;
                // }



                that.setData({
                    nianList: res.data
                }, () => {
                    if (that.data.nianList.length) {
                        var json = {
                            name: '暂不使用',
                            isSelect: false,
                            validTime: '666',
                            payRate: 1,
                        };


                        that.data.nianList.unshift(json)
                        var min = Math.min.apply(Math, res.data.map(function (o) {
                            return o.payRate;
                        }))
                        console.log("最小的z折扣---", min); // 2
                        for (var i = 0; i < that.data.nianList.length; i++) {
                            if (parseFloat(that.data.nianList[i].payRate) == min) {
                                console.log('fff====');
                                that.data.nianList[i].isSelect = true;
                                that.setData({
                                    cardVipJson: that.data.nianList[i],
                                    currentCardSelectIndex: i,
                                    currentVipDiscount: min
                                })
                            }
                        }



                        // that.typeList(that.data.nianList[0].annualCardId) //轮播第一条数据
                        that.setData({
                            nianList: that.data.nianList,
                            memeberSelect: true,
                            hasBuy: true,
                            cardVipShow: true,

                        }, () => {
                            // that.Nian_ca()
                            console.log('nianList===', that.data.nianList);
                        })
                    }
                })
            } else {
                common.showRequestErrMsg(res)
            }
        })
    },
    // 时间戳
    time(time) {
        return common.dateFormat('yyyy-MM-dd', time)
    },
})